package com.chixing.day05;

public class Work4 {
    private static boolean isPrime(int num) {
        if (num <= 1) {
            return false;
        }
        for (int i = 2; i * i <= num; i++) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }
    public static int[] find(int[] a){
        boolean isFirst=true;
        a=bubboSort(a);
        System.out.print("[");
        for(int i=0;i< a.length;i++){

            if (isPrime(a[i])==true) {
                if(!isFirst){
                System.out.print( ","+a[i]);
            }else {
                    isFirst=false;
                    System.out.print(a[i]);
                }
            }
        }
        System.out.println("]");
        return a;
    }
    public static int[] bubboSort(int[] a) {
        for (int i = 0; i < a.length -1;i++) {
            for (int j = 0; j < a.length - i - 1; j++) {
                if (a[j] > a[j + 1]) {
                    int temp = a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = temp;
                }
            }
        }
        return a;
    }

    public static void main(String[] args) {
        int[]a={3,1,4,2,8,11,15,17};
        find(a);
    }
}
